package pokerserver.core;

import pokerserver.core.network.ServerThread;
import common.GameAction;
import common.Message;

/**
 * An interface which describes all actions the server may perform towards its
 * clients. Note that all actions performed by the server require requests from
 * a client.
 * 
 */
public interface IServer {

	/**
	 * return a message with a field containing all player nicknames
	 * 
	 * @param client
	 * @return
	 */
	public abstract Message getGameStateMessage(ServerThread client);

	/**
	 * sets the nickname of a certain player
	 * 
	 * @param client
	 * @param nickname
	 */
	public abstract void setNickname(ServerThread client, String nickname);

	/**
	 * perform the action specified by the client player
	 * 
	 * @param client
	 * @param action
	 */
	public abstract void doAction(ServerThread client, GameAction action);

	/**
	 * Tell the clients which player won a game
	 */
	public abstract void announceWinner();

	/**
	 * Close connection
	 * 
	 * @param client
	 */
	public abstract void removePlayer(ServerThread client);

	/**
	 * Advance the game to the next betting stage
	 */
	public void advanceGame();

	/**
	 * Hands out the pot amount to the right player(s).
	 */
	public void handOutPot(Player[] winners);

	/**
	 * Creates a new (reshuffled) deck.
	 */
	public void newDeck();

	/**
	 * This method adds a player to the game, and sets its position. This can
	 * only be done if the game haven't already started., and if there is room
	 * enough.
	 * 
	 * @param player
	 *            The player to add
	 * @throws IndexOutOfBoundsException
	 */
	public void addPlayer(Player player) throws IndexOutOfBoundsException;

	/**
	 * Called when a round is finished. simply deals new cards, and resets
	 * everything except the stacks.
	 */
	public void newRound();

	/**
	 * Lets the next player do his turn
	 */
	public void nextPlayer();

	/**
	 * Player p chooses to perform a game related action:
	 * 
	 * @param p
	 */
	public void call(Player p);

	/**
	 * 
	 * @param p
	 */
	public void check(Player p);

	/**
	 * 
	 * @param p
	 */
	public void allIn(Player p);

	/**
	 * 
	 * @param p
	 */
	public void fold(Player p);

	/**
	 * 
	 * @param player
	 * @param bet
	 */
	public void bet(Player player, int bet);

	/**
	 *  Handles incoming requests to start the game:
	 * @param client
	 * @return
	 */
	public boolean startGame(ServerThread client);

}
